import 'package:flutter/material.dart';

import 'app_btn.dart';

/// app列表项封装
class AppListTile extends StatelessWidget {
  const AppListTile({
    Key? key,
    this.leading,
    this.title,
    this.subtitle,
    this.trailing,
    this.onTap,
    this.height,
    this.titleText,
    this.subtitleText,
    this.padding,
    this.contentColor,
    this.backgroundColor,
    this.radius,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.onLongPress,
    this.borderRadius,
  }) : super(key: key);

  final Widget? leading;
  final Widget? title;
  final Widget? subtitle;
  final Widget? trailing;

  final Function()? onTap;
  final Function()? onLongPress;
  final double? height;

  final String? titleText;
  final String? subtitleText;

  final EdgeInsetsGeometry? padding;
  final Color? contentColor;
  final Color? backgroundColor;
  final double? radius;
  final BorderRadiusGeometry? borderRadius;

  final CrossAxisAlignment crossAxisAlignment;

  @override
  Widget build(BuildContext context) {
    Widget child = Column(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: <Widget>[
        title ??
            (titleText == null
                ? const SizedBox.shrink()
                : Text(
                    titleText!,
                    style: const TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.w500,
                    ),
                  )),
        if (subtitle != null || subtitleText != null)
          subtitle ??
              (subtitleText == null
                  ? const SizedBox.shrink()
                  : Text(
                      subtitleText!,
                      style: TextStyle(
                        fontSize: 11,
                        color: Theme.of(context).disabledColor,
                      ),
                    )),
      ],
    );

    if (leading != null || trailing != null) {
      child = Row(
        crossAxisAlignment: crossAxisAlignment,
        children: <Widget>[
          if (leading != null) leading!,
          Expanded(child: child),
          if (trailing != null) trailing!,
        ],
      );
    }

    if (onTap != null || onLongPress != null || padding != null) {
      child = AppBtn(
        onTap: onTap,
        onLongPress: onLongPress,
        child: child,
        color: backgroundColor ?? Colors.transparent,
        radius: radius,
        padding: padding ?? EdgeInsets.zero,
        borderRadius: borderRadius,
      );
    }

    if (height != null) {
      child = SizedBox(height: height, child: child);
    }

    return child;
  }
}
